<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>
          <el-col :span="5" style="padding-top: 10px;">
            个人信息
          </el-col>
          <el-col :span="18">
            <el-dropdown trigger="click" style="float: right;" @command="handleCommand">
              <el-button icon="el-icon-edit" size="small" type="text"/>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="pwd">修改密码</el-dropdown-item>
                <el-dropdown-item command="info">修改信息</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>
        </el-row>
      </div>
      <div>
        <div class="text item fl">
          <ul style="padding-left:0px;list-style:none ">
            <li style="margin:5px;">{{ account.accountName }}</li>
            <li style="margin:5px;">
              <svg-icon icon-class="ren"/> {{ account.truename }} /
              <span v-for="role in account.roles" :key="role">
                {{ role }}
              </span>
            </li>
            <li style="margin:5px;">
              <svg-icon icon-class="weibiaoti-"/> {{ account.phone }}
            </li>
            <li style="margin:5px;">
              <svg-icon icon-class="xingbie"/> {{ account.sex === 0 ? '女':'男' }}
            </li>
            <li style="margin:5px;">
              <svg-icon icon-class="nianling"/> {{ account.age }}
            </li>
            <li style="margin:5px;">
              <svg-icon icon-class="shijian"/> {{ account.createTime }}
            </li>
          </ul>
        </div>
        <div class="item headimg fr">
          <img :src="account.headImg" class="user-avatar">
        </div>
      </div>
    </el-card>
    <!-- 密码设置 -->
    <editPwd v-if="editPwdFormVisible" ref="editPwdDialog"/>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import editPwd from './editPwd'

export default {
  name: 'UserCenter',
  components: { editPwd },
  computed: {
    ...mapGetters([
      'account'
    ])
  },
  data() {
    return {
      editPwdFormVisible: false
    }
  },
  methods: {
    handleCommand: function(command) {
      console.log(command)
      switch (command) {
        case 'pwd':
          console.log('11111')
          this.editPwdFormVisible = true
          this.$nextTick(() => {
            this.$refs.editPwdDialog.init(this.account.accountId)
          })
          break
        default:
          break
      }
    }
  }
}
</script>

<style scoped>
  .text {
    font-size: 14px;
  }

  .fl {
    float: left;
  }

  .fr {
    float: right;
  }

  .headimg {
    margin-top: 10px;
    text-align: center;
    vertical-align: middle;
  }

  .item {
    margin-bottom: 10px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    margin-left: 10px;
    margin-top: 10px;
    width: 480px;
  }

  .inline {
    display: inline;
  }
</style>
